package com.gy.education.home;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.gy.education.BaseActivity;
import com.gy.education.R;
import com.gy.education.home.adapter.MyMessageAdapter;
import com.gy.education.home.bean.MessageBean;
import com.gy.education.utils.AnimUtil;
import com.library.PullToRefreshBase;
import com.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：gy on 16/7/13
 * 说明：私信
 */
public class MyMessageActivity extends BaseActivity {

    private PullToRefreshListView listView;
    private MyMessageAdapter adapter;
    private List<MessageBean> list;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_my_message);
        setTitleMsg("私信");
        listView = (PullToRefreshListView) findViewById(R.id.message_listview);
    }

    @Override
    protected void initData() {
        list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new MessageBean());
        }
        adapter = new MyMessageAdapter(this,list);
    }


    @Override
    protected void setListener() {
        super.setListener();
        listView.setMode(PullToRefreshBase.Mode.BOTH);
        listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                complateHandler.sendEmptyMessageDelayed(0,200);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                complateHandler.sendEmptyMessageDelayed(0,200);
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(MyMessageActivity.this,MessageDetailActivity.class);
                intent.putExtra("name","选课通知");
                intent.putExtra("detail","这学期的课程已经可以选课了,请同学们抓紧时间选课");
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(MyMessageActivity.this);
            }
        });
    }

    @Override
    protected void fillData() {
        super.fillData();
        listView.setAdapter(adapter);
    }

    private Handler complateHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            listView.onRefreshComplete();
        }
    };
}
